<?php

function isValidEmail($email) {
	return eregi ( "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email );
}

function isValidAgegroup($agegroup) {
    if (!isset($agegroup) || $agegroup == "") {
        return false;
    }
    return ereg("^ *[Uu](6|8|9|10|11|12|13|14|15|16|17|18|19)[bBgG] *$", $agegroup);
}

function isValidPhone($var, $emptyok = 0) {
	if ($var == "" && $emptyok) {
		return 1;
	}
	return ereg ( "^ *(([0-9]{3} *(-|/|\.)? *)|(\( *[0-9]{3} *\) *(-|/|.)? *))?[0-9]{3} *(-|/|\.)? *[0-9]{4} *$", $var );
}

function isValidDate($date, $emptyok = 0) {
	if ($date == "" && $emptyok) {
		return true;
	}
	return ereg ( "^ *(((1[0-2])|(0?[1-9])) *(-|/|\.) *)(((3[0-1])|([1-2][0-9])|(0?[1-9])) *(-|/|\.) *)(20)?[0-9]{2} *$", $date );
}

function nino1() {
	return "ninoborsoni49@comcast.net"; 
}

function nino() {
	return "nborsoni@gmail.com";
}

function removeSpaces($a) {
	return str_replace ( " ", "", $a );
}

function shortmail($to, $subject, $text) {
	mail ( $to, $subject, $text );
}

function maxmail($to, $from, $subject, $text, $html = 0) {
	$t = $text;
	
	$t = str_replace ( "</body>", "", $t );
	$t = str_replace ( "<body>", "", $t );
	$t = str_replace ( "</html>", "", $t );
	$t = str_replace ( "<html>", "", $t );
	
	$head = "From: $from\n";
	if ($html == 1) {
		
		$t = "<html><body>$t</body></html>";
		$lines = explode ( "<", $t );
		$count = count ( $lines );
		$tt = "";
		for($i = 1; $i < $count; $i ++) {
			//$line = $lines[$i] . ">";
			$line = "<" . $lines [$i];
			$len = strlen ( $line );
			for($j = $len; $j < 990; $j ++) {
				$line .= " ";
			}
			$tt = $tt . $line . "\r\n";
		}
		$wrap = $tt;
		
		$head = $head . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1" . "\n";
	} else {
		$wrap = $t;
	}
	mail ( $to, $subject, $wrap, "To: " . $to . "\n" . $head );
	/*
    mail("mlchiodo@gmail.com", "TTTT", $tt, "To: mlchiodo@gmail.com\n".$head);
    mail("mchiodo@cadence.com", "CCCC", $tt, "To: mchiodo@cadence.com\n".$head);
     */
	
	return 0;
}

function setwidth($w = 140) {
	echo "<p>";
	for($i = 0; $i < $w; $i ++) {
		echo "&nbsp;";
	}
}

function headtab($name, $link, $ext = 0) {
	if ($ext == 0) {
		$link = "box1.php?page=" . $link;
	}
	echo <<<TOKEN
<td class=blueBox style="padding:0px";>
<div class=link2>
<a href="
TOKEN;
	echo $link;
	echo <<<TOKEN
" style="text-decoration:none;">
<div class=blueBox style="background-color:#222222;padding:2px;">
<div class=blueBox 
style='color:#000000;background-color:#ccaa22;background-size:180px;padding:4px;'
onmouseout="style.backgroundColor='#ccaa22'" 
onmouseover="style.backgroundColor='#aa7722'" 
>
<center><strong>&nbsp;&nbsp;&nbsp;
TOKEN;
	echo $name;
	echo <<<TOKEN
&nbsp;&nbsp;&nbsp;</strong></center>
</div></div></a></div></td>
TOKEN;
	echo '<td class=blueBox style="padding:1px;"></td>';
}

function navline($page, $title, $here, $ext = 0) {
	$link = $here;
	if ($ext == 0) {
		$link = "box1.php?page=" . $link;
	}
	$xtyle = " style=\"font-weight:bold;color:#bbbbbb;background-color:#00000a;\" ";
	$prefix = strtok ( $page, "_" );
	$link1 = " class=link1 ";
	$a = "</a>";
	$load = "onload=\"style.fontWeight='bold';style.color='#bbbbbb';style.backgroundColor='#00000a'\" ";
	$out = "onmouseout=\"style.fontWeight='bold';style.color='#bbbbbb';style.backgroundColor='#00000a'\" ";
	$over = "onmouseover=\"style.fontWeight='bold';style.color='#bbbbbb';style.backgroundColor='#42526f'\" ";
	$xtyle = " style=\"font-weight:bold;color:#bbbbbb;background-color:#000000a;\" ";
	$ahref = "<a " . $xtyle . " href=\"" . $link . "\">";
	if ($prefix == $here) {
		$load = "";
		$out = "";
		$over = "";
		$link1 = " class=link2 ";
		$xtyle = " style=\"font-weight:bold;color:#000000;background-color:#aaaa33;\" ";
		$ahref = "<a " . $xtyle . " href=\"" . $link . "\">";
		if ($page == $here) {
			$xtyle = " style=\"font-weight:bold;color:#000000;background-color:#aaaa33;\" ";
			$ahref = "";
			$a = "";
			$link1 = " class=link1 ";
		}
	}
	$oo = $over . $out . $load;
	
	echo "<tr><td class=blueBox>";
	addnbsp ( 4 );
	echo "</td>";
	
	echo "<td class=tab " . $xtyle . $oo . ">" . "<div " . $link1 . ">" . "<div class=tab " . $xtyle . $oo . ">" . $ahref . $title . $a . "</div>" . "</div>" . "</td>" . "</tr>";

		//echo "<div class=blueBox " . $xtyle . $oo . ">" . $ahref  . $title . $a . "</div></td></tr>";
}

function show($show, $width, $height) {
	echo <<<TOKEN

<script language="JavaScript" type="text/javascript">
<!--
if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
    alert("This page requires AC_RunActiveContent.js.");
} else {
    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if(hasRightVersion) { 
        AC_FL_RunContent(
            'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
            'width', '$width',
            'height', '$height',
            'scale', 'noscale',
            'salign', 'TL',
            'bgcolor', '#ffffff',
            'wmode', 'opaque',
            'movie', '../slickboard/slickboard',
	    'src', '../slickboard/slickboard',
TOKEN;
	echo "'FlashVars', 'xml_source=$show.xml',";
	echo <<<TOKEN
            'id', 'my_board',
            'name', 'my_board',
            'menu', 'true',
            'allowFullScreen', 'true',
            'allowScriptAccess','sameDomain',
            'quality', 'high',
            'align', 'middle',
            'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
            'play', 'true',
            'devicefont', 'false'
            ); 
    } else { 
        var alternateContent = 'This content requires the Adobe Flash Player. '
        + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
        document.write(alternateContent); 
    }
}
// -->
</script>
<noscript>
    <P>This content requires JavaScript.</P>
</noscript>
TOKEN;

}

function addnbsp($n, $br = 0) {
	for($i = 0; $i < $n; $i ++) {
		echo "&nbsp;";
		if ($br === 1) {
			echo "<br/>";
		}
	}
}

function showt($s) {
	echo <<<TOKEN
<script type="text/javascript">
var txtfiles = new Array();

TOKEN;
	$max = 99;
	$n = 1;
	$ver = 18; // increase this every time you change a picture
	echo 'txtfiles[0] = "0000";' . "\n";
	for($n = 1; $n <= $max; $n ++) {
		if (! file_exists ( "../$s/$n.txt" )) {
			continue;
		}
		echo 'txtfiles[' . $n . '] = "';
		echo trim ( file_get_contents ( "../$s/$n.txt" ) );
		echo "\";\n";
	}
	echo <<<TOKEN
function load() {
    printShow();
}
function printShow() {
document.getElementById('shw1a').innerHTML="<p><img src=\"../
TOKEN;
	echo $s;
	echo <<<TOKEN
/"+whatSlide+".jpg?q=
TOKEN;
	echo "$ver";
	echo <<<TOKEN
\" width=360 /></p>";
document.getElementById('shw1b').innerHTML=txtfiles[whatSlide];
t=setTimeout('printShow()',14000);
whatSlide = whatSlide + 1;
if (whatSlide > maxSlide_
TOKEN;
	echo $s;
	echo <<<TOKEN
) {
    whatSlide = 1;
}
}
</script>
TOKEN;

}

function bioline($first, $last, $image, $title, $email, $bio) {
	echo <<<TOKEN
<tr><td class=whiteBox><p><strong> 
TOKEN;
	echo $first . " " . $last;
	echo <<<TOKEN
</strong></p><p><img alt="" 
src="../images/
TOKEN;
	echo $image;
	echo <<<TOKEN
" 
style="float: left" width="70" height="97"></p> 
<br/><br/> 
<p>
TOKEN;
	echo $title;
	echo <<<TOKEN
</p></td><td class=whiteBox><p><b>
TOKEN;
	echo $first . " </b>";
	echo $bio . "</p>";
	echo "</td></tr>";
}

function title($text) {
	echo "<h1>$text</h1>";
	$here = $_SERVER ['REQUEST_URI'];
	$to = strripos ( $here, "_" );
	if ($to === FALSE) {
		return;
	}
	$pageup = substr ( $here, 0, $to );
	echo "<p><a href='$pageup'><img border=0  src='../images/up.jpg'></a></p>";
}

function announce() {
	if (0) {
		echo <<<TOKEN
<table rules=none border=0>
<tr><td class=whiteBox>
<a href='box1.php?page=../articles/article3'>
<p class=whiteBox style="background-color:#ddeeee;color:blue;">
<strong>Bay Area Soccer Winter Camp 2010</strong><br/>
For ages 8-14<br/>
at Bishop O'Dowd High School<br/>
Dec 29-31 9am-12pm
</p>
</a>
</td></tr></table>
TOKEN;
	}
}

function closedfields() {
	echo <<<TOKEN
<table rules=none border=0>
<tr><td class=whiteBox>
<p style="background-color:red;color:white;">
&nbsp; <br/>
&nbsp; WEATHER ALERT! Fields may be closed <br/>
&nbsp; for practice (Mon-Fri) due to bad weather.<br/>
&nbsp; Make sure you have up to date information <br/>
&nbsp; from your coach/manager.<br/>
&nbsp; <br/>
</p>
<a href="http://www.jlysl.org">
<p>
<strong>Weekend Rainout Notifications </strong><br/>
Visit the JLYSSL website, or <br/>
call the JLYSSL Rainout Hotline (510)812-6051.
</p>
</a>
<p>
<strong>
Weekday Rainout Notifications </strong><br/>
You will receive a field closure status message<br/>
via Team Snap. Any such notice may also be <br/>
posted on the Bay Oaks Soccer Club website.
</p>
</td></tr></table>
TOKEN;
}

function item($title, $text, $link) {
	echo '<tr>';
	echo '<td class=whiteBox><a href="' . $link . '"><img border=0 src="../images/hand.jpg" /></a></td>';
	echo '<td class=whiteBox style="background-color:#eeeeee"><a href="' . $link . '"><b>' . $title . '</b><br/>' . $text . '</a></td>';
	echo '</tr>';
}

function record_unique_id($fn) {
	
        $wcout = trim(shell_exec("wc -l " . $fn));
        $wctok = explode(" ", $wcout);
        $len = $wctok[0] + 1;
        $idstr = "ID " . $len . " --- " . date('D, d M Y H:i:s') . " ";
        system("echo '" . $idstr . "' >> " . $fn);
        return $idstr;
}

function gen_temp_id() {
	
	return "".time().rand(0,20)."";
}

function dump_to_file($fn, $text) {
    file_put_contents ( $fn, $text );
    return 0;
}

function getFormDataNotEmpty($method,$name,&$ok) {
    $data = "";
    if ($method == 'POST') {
        $data = $_POST[$name];
    }
    if ($method == 'GET') {
        $data = $_GET[$name];
    }
    if (!isset($data)) {
        $data = "<b>(MISSING)</b>";
        $ok = 0;
    }
    if ($data == "") {
        $data = "<b>(MISSING)</b>";
        $ok = 0;
    }
    return $data;
}


?>
